{% extends "showinfo/base.html" %}

{% block content %}




    <div class="form-group">
        <label class="col-lg-3 control-label">身份证号码</label>

        <div class="col-lg-4">
            <input type="number" class="form-control" name="idcard" id="idcard" placeholder="身份证号码"/>
        </div>
        <div class="col-lg-4">
            <input type="button" class="btn btn-primary" value="查看" onclick="getdata()"></button>
        </div>
    </div>
    <br/>
    <br/>
    <br/>

    <div class="alert alert-success" role="alert" id="msg">


    </div>




    <script>
        String.format = function (src) {
            if (arguments.length == 0) return null;
            var args = Array.prototype.slice.call(arguments, 1);
            return src.replace(/\{(\d+)\}/g, function (m, i) {
                return args[i];
            });
        };
        function getdata() {
            var url = "{% url "getapis:idcard" "gg" %}";

            var idcard = $("#idcard").val();
            if (idcard.length == 0) {
                idcard = "53018119720912109X";
            }

            url = url.replace("gg", idcard);

            $.getJSON(url, function (result) {
            console.log(result);
               if(result.errNum==-1)
               {
                   alert(result.retMsg);
                   return false;
               }
                    var sex = "女";
                    if (result.retData.sex == "M") {
                        sex = "男";
                    }
                    var s = "性别:{0}<br />生日:{1}<br />地址:{2}<br />";
                    var res = String.format(s, sex, result.retData.birthday, result.retData.address);
                    console.log(res);
                    $("#msg").html(res);


            });

        }
 $(function () {
            getdata();

        });

    </script>




{% endblock %}